package com.servlet;

import com.Dao.AdminDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "UpdateInfoServlet", value = "/UpdateInfoServlet")
public class UpdateInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String userName =request.getParameter("username");
        String password = request.getParameter("password");
        String password2 = request.getParameter("password2");
        String name = request.getParameter("name");
        String sex= request.getParameter("sex");
        String email=request.getParameter("email");
        AdminDao adminDao=new AdminDao();
        try {
            boolean flag =adminDao.oldPassword(password);
            if (flag) {
                adminDao.updateInfo(userName, name,password2,email,sex);
                response.sendRedirect("index_admin.jsp");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
